﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using SalePartial.Utility;
using System.Data;
using SalePartial.Model;
using SalePartial.IDAL;

namespace SalePartial.SQLServerDAL
{

    //<DataObject(True)> _
    public class XPNotification : IXPNotification
    {
        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int Delete(Guid NotifyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("NotifyID", NotifyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByCreateUserID(Guid CreateUserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CreateUserID", CreateUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsDeleteByCreateUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByRecipientUserID(Guid RecipientUserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("RecipientUserID", RecipientUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsDeleteByRecipientUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPNotificationInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("NotifyID", info.NotifyID),
			new SqlParameter("CreateUserID", info.CreateUserID),
			new SqlParameter("RecipientUserID", info.RecipientUserID),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("SendDate", info.SendDate),
			new SqlParameter("LastSaveDate", info.LastSaveDate),
			new SqlParameter("Status", info.Status),
			new SqlParameter("ReadDate", info.ReadDate),
			new SqlParameter("ReplyDate", info.ReplyDate),
			new SqlParameter("TargetID", info.TargetID),
			new SqlParameter("ContentType", info.ContentType),
			new SqlParameter("Title", info.Title),
			new SqlParameter("BodyText", info.BodyText),
			new SqlParameter("Attachment", info.Attachment)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectAll]", parameters, "XPNotification_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByCreateUserID(Guid CreateUserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CreateUserID", CreateUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectByCreateUserID]", parameters, "XPNotification_ByCreateUserID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByRecipientUserID(Guid RecipientUserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("RecipientUserID", RecipientUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectByRecipientUserID]", parameters, "XPNotification_ByRecipientUserID");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectDynamic]", parameters, "XPNotification_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectPaged]", parameters, "XPNotification_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReader(Guid NotifyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("NotifyID", NotifyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationSelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByCreateUserID(Guid CreateUserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CreateUserID", CreateUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectByCreateUserID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByRecipientUserID(Guid RecipientUserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("RecipientUserID", RecipientUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationsSelectByRecipientUserID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectSingle(Guid NotifyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("NotifyID", NotifyID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPNotificationSelect]", parameters, "XPNotification_Single");
            DataTable dt = ds.Tables["XPNotification_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPNotificationInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("NotifyID", info.NotifyID),
			new SqlParameter("CreateUserID", info.CreateUserID),
			new SqlParameter("RecipientUserID", info.RecipientUserID),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("SendDate", info.SendDate),
			new SqlParameter("LastSaveDate", info.LastSaveDate),
			new SqlParameter("Status",info. Status),
			new SqlParameter("ReadDate", info.ReadDate),
			new SqlParameter("ReplyDate", info.ReplyDate),
			new SqlParameter("TargetID", info.TargetID),
			new SqlParameter("ContentType", info.ContentType),
			new SqlParameter("Title", info.Title),
			new SqlParameter("BodyText", info.BodyText),
			new SqlParameter("Attachment",info. Attachment)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPNotificationUpdate]", parameters, RowsAffected);
        }

    }



}
